#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# input and output
print("----------%s------------", "input and output")
name = input("please enter youer name:")
print("hello,", name)

# String output and 转义(\)与保留(r"") and multi line output'''...'''
print("----------%s------------", "multi line")
print("I\'m OK")
print(r"I\'m OK")
print("line1"
      "line2"
      "line3")

print("""line1
... line2
... line3""")

print('''line1
line2
line3''')

# 常量定义 and 取整除法
print("----------%s------------", "variable")
PI = 3.14
print(10 / PI)
print(10 // PI)

# 中文
print("----------%s------------", "ascii unicode utf-8")
print("石栋梁".encode("utf-8", errors="ignore"))
print(len(b"\x0f".decode("utf-8")))

# 字符格式化输出%
print("----------%s------------", "format character/float")
print("hello, %s %d%%" % ("world", 100))

clast = 72
cnow = 85
print("提升比率:%.3f" % (cnow / clast))

# 数组
print("----------%s------------", "list and tuple")
listAry = [
    ["apple", "google", "microsoft"],
    ["java", "python", "ruby"]
]

# can not change array
L = (1, 2, (3, 4), (5,))

print(listAry[0][0])
print(listAry[1][2])
listAry[1][2] = "php"
print(listAry[1][2])

print(L[1])
print(L[2][1])
print(L[3][0])
# L[3][0] = 6

# if else
print("----------%s------------", "if else")
age = 10
if age >= 40:
    print("old man! your age is:", age)
elif 20 <= age < 40:
    print("young man!")
else:
    print("child!")

# BMI指数测试
print("----------%s------------", "BMI指数")
high = input("请输入你的身高(cm):")
wight = input("请输入你的体重(kg):")
bmi = int(wight) / (int(high) * int(high) / 1e4)
print("BMI指数: %.2f" % bmi)
if bmi < 18.5:
    print("太瘦")
elif 18.5 <= bmi < 25:
    print("标准")
elif 25 <= bmi < 28:
    print("偏胖")
elif 28 <= bmi < 32:
    print("肥胖")
elif 32 < bmi:
    print("过渡肥胖")

# 循环
print("----------%s------------", "循环 for while")
ary = list(range(100))
sum = 0
for num in ary:
    sum += num + 1
print("result: %d" % sum)

num = 100
sum = 0
while num > 0:
    sum += num
    num -= 1
    if num <= 50:
        break
print("result: %d" % sum)

# 集合
print("----------%s------------", "dict->map set")

aMap = dict()
aMap["name"] = "test"
print(aMap["name"])

aMap = {"id": "23213", "name": "sdl", "age": 30}
print(aMap.get("age", 20))

aMap.pop("age")
print(aMap.get("age", 20))

aMap.popitem()
print(aMap.get("name", "lbq"))

aSet = aMap.keys()

for key in aSet:
    print(key)

aSet = set([1, 1, 2, 3, 3])

aSet.add(5)
aSet.remove(1)

print(aSet)
